
import PopupBase from "./PopupBase";
import PopManager from "./PopManager";
import ASdk from "../SdkAll";
import * as UserManager from "../../scripts/UserManager.js"
import * as EventConst from "../../scripts/EventConst.js"
import * as lingqu from "../../scripts/Win.js"
import * as EventManager from "../../scripts/EventManager.js"
import ad from "../ad";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Pop extends PopupBase<ConfirmPopupOptions> {
    
    @property(cc.Label)
    private titleLabel: cc.Label = null;

    @property(cc.Label)
    private contentLabel: cc.Label = null;

    @property(cc.Node)
    private confirmBtn: cc.Node = null;

    @property(cc.Node)
    private right: cc.Node = null;

    private isright = false
    public static get path() { return 'pre/pop'; }

    protected onLoad() {
        this.confirmBtn.on('touchend', this.onConfirmBtnClick, this);
    }

    protected updateDisplay(options: ConfirmPopupOptions) {
        // this.titleLabel.string = options.title; // this.options.title 也行
        // this.contentLabel.string = options.content;  // this.options.content 也行
    }

    private onConfirmBtnClick() {
        this.hide();
        // PopupManager.show('pre/pop');

        // PopupManager.show('pre/pop');

    }
    // 设为常用
    async addCommonUse() {
        this.hide()
        await ASdk.addCommonUse()
        // 红点消失
        cc.game.emit('leftPoint')
        // 发放奖励
        this.getReward()
        // UserManager.set('key',10)
        // UserManager.User.data.key+=10
        // UserManager.User.__proto__.save()
        // cc.sys.localStorage.setItem(
        //     "walkFast" + "_" + "key",
        //     JSON.stringify(UserManager.User.data.key)
        //   );
        // cc.game.emit('event_10')
        // UserManager.User.__proto__.set('key',10)
        
        
    }
    // 添加到桌面
    async addDes(){
        this.hide()
        await ASdk.addShortcut()
        cc.game.emit('rightPoint')

        this.getReward()
    }
    getReward(){
        UserManager.User.data.key+=1
        UserManager.User.__proto__.save()
        cc.sys.localStorage.setItem(
            "walkFast" + "_" + "key",
            JSON.stringify(UserManager.User.data.key)
          );
        cc.game.emit('event_10')
    }
    // private receive() {
    //     if (!this.right.active) return
    //     this.hide();
    //     // 接受用户协议  切换到主场景
    //     // MdGame.inst.showView();
    //     // LData.privacy=0
    // }
    // private refuse(){
    //     // 拒绝用户协议   关闭游戏
    //     cc.game.end()
    // }
    // private updateBtn()
    // {
    //     this.right.active=this.isright
    //     this.isright=!this.isright
    // }
    // private PriAgreement(){
    //     // 隐私协议
    //     this.hide()
    //     PopupManager.show('pre/privacy');

    // }
    // private UAgreement(){
    //     // 用户协议
    //     this.hide()
    //     PopupManager.show('pre/UAgreement');
    // }
}

export type ConfirmPopupOptions = {
    title: string;
    content: string;
}